﻿#region Imports
using System.Windows;
using System.Windows.Forms;
using CommonUtilities.Extensions;
#endregion

// RKD - many
namespace DirectoryAnalyzer.Controls
{
    /// <summary>
    /// Interaction logic for Expander.xaml
    /// </summary>
    public partial class Expander : System.Windows.Controls.UserControl
    {
        #region Properties
        public string ToggleButtonText
        {
            get { return txtbHeader.Text; }
            set { txtbHeader.Text = value; /*RaisePropertyChanged("ToggleButtonText");*/ }
        }

        public bool? IsToggleChecked
        {
            get { return chkSilent.IsChecked; }
            set
            {
                chkSilent.IsChecked = value; /*RaisePropertyChanged("IsToggleChecked");*/
                //ToggleButtonText = chkSilent.IsChecked.HasValue ? (chkSilent.IsChecked.Value ? TextTrue : TextFalse) : TextFalse;

                switch (chkSilent.IsChecked.GetCheckState())
                {
                    case CheckState.Checked:
                        ToggleButtonText = TextTrue;
                        break;

                    case CheckState.Unchecked:
                        ToggleButtonText = TextFalse;
                        break;

                    case CheckState.Indeterminate:
                    default:
                        ToggleButtonText = HasThreeState ? TextMixed : TextFalse;
                        break;
                }
            }
        }

        public static string textTrue = "True -> False";
        /// <summary>
        /// Text to display when 'toggle' value is 'true'
        /// <para>Hint: Directs user to select button to perform actions to make it 'false'</para>
        /// </summary>
        public string TextTrue
        {
            get { return textTrue; }
            set { textTrue = value; /*RaisePropertyChanged("TextTrue");*/ }
        }

        public static string textFalse = "False -> True";
        /// <summary>
        /// Text to display when 'toggle' value is 'false'
        /// <para>Hint: Directs user to select button to perform actions to make it 'true'</para>
        /// </summary>
        public string TextFalse
        {
            get { return textFalse; }
            set { textFalse = value; /*RaisePropertyChanged("TextFalse");*/ }
        }

        private string textMixed = "Mixed (null)";
        public string TextMixed
        {
            get { return textMixed; }
            set { textMixed = value; }
        }

        public bool HasThreeState
        {
            get { return chkSilent.IsThreeState; }
            set { chkSilent.IsThreeState = value; }
        }
        #endregion

        #region Constructors
        public Expander()
        {
            InitializeComponent();
        }
        #endregion

        bool isLoading = false;
        private void expExpander_StateChanged(object sender, RoutedEventArgs e)
        {
            isLoading = true;
            e.Handled = false;
            //if (!HasThreeState) IsToggleChecked = expExpander.IsExpanded;

            chkSilent.IsChecked = !chkSilent.IsChecked.GetValueOrDefault(false);
            //switch (chkSilent.IsChecked.GetCheckState()) // RKD
            //{
            //    case CheckState.Checked:
            //    case CheckState.Unchecked:
            //        chkSilent.IsChecked = !chkSilent.IsChecked;
            //        break;
            //
            //    case CheckState.Indeterminate:
            //    default:
            //        chkSilent.IsChecked = false;
            //        break;
            //}

            isLoading = false;
        }

        private void chkSilent_Checked(object sender, RoutedEventArgs e)
        {
            IsToggleChecked = chkSilent.IsChecked;
        }
    }
}
